﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Data;
using Matrix.Common.Utility;
using Matrix.MaKaYunShang.Model;
using Matrix.MaKaYunShang.DAL;
using Matrix.MaKaYunShang.Model.Dto;

namespace Matrix.MaKaYunShang.BLL
{
    public partial class OrderCommentBLL : BaseBLL<OrderCommentBLL>
    {
        #region 默认方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(OrderComment model)
        {
            return OrderCommentDAL.Instance.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(OrderComment model)
        {
            return OrderCommentDAL.Instance.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {
            return OrderCommentDAL.Instance.Delete(Id);
        }
        /// <summary>
        /// 批量删除一批数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return OrderCommentDAL.Instance.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public OrderComment GetModel(int Id)
        {
            var ds = OrderCommentDAL.Instance.GetModel(Id);
            return ds == null ? null : ServicesHelper.DataSetToIList<OrderComment>(ds).ToList()[0];
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<OrderComment> GetModelList(string strWhere = null)
        {
            var ds = OrderCommentDAL.Instance.GetList(strWhere);
            return ServicesHelper.DataSetToIList<OrderComment>(ds).ToList();
        }
        #endregion

        #region 扩展方法
        /// <summary>
        ///获得分页数据列表
        /// </summary>
        public TableDataViewDto<ViewOrderCommentDto> GetPagingList(int draw, int pageIndex, int pageSize, string searchKeyWord, string colOrder)
        {
            try
            {
                int totalCount = 0;
                List<ViewOrderCommentDto> list = OrderCommentDAL.Instance.GetPagingList(pageIndex, pageSize, searchKeyWord, colOrder, ref totalCount);
                list.ForEach(a =>
                {
                    var acrion = string.Empty;
                    if(a.Points<3&&string.IsNullOrEmpty(a.DealResult))
                    {

                        acrion = "   <a class='btn btn-warning'  data-toggle='modal' data-target='#myModal' href='javascript:;' onclick=HandleProblems(" + a.Id + ","+a.ConsumerId+");>处理问题</a>";
                    }
                    if(!string.IsNullOrEmpty(a.DealResult))
                    {
                        acrion = "<a class='btn btn-info' href='javascript:;' onclick='HandleResult(" + a.Id + ")';>处理结果</a>";
                    }
         
                    a.Action =acrion;
                    a.AddTimeStr = a.AddTime.ToString();
              
                });
                var returnDataList = new TableDataViewDto<ViewOrderCommentDto>
                {
                    data = list,
                    draw = draw,
                    recordsFiltered = totalCount,
                    recordsTotal = totalCount
                };

                return returnDataList;
            }
            catch (Exception ex)
            {
                _fileLog.Error(" GetPagingList | Exception: " + ex);
                return null;
            }
        }

        /// <summary>
        /// 根据订单Id得到一个对象实体
        /// </summary>
        /// <remarks>2016-09-02 万乐园 创建</remarks>
        public OrderComment GetModelByOrderId(int orderId)
        {
            var ds = OrderCommentDAL.Instance.GetModelByOrderId(orderId);
            return ds == null ? null : ServicesHelper.DataSetToIList<OrderComment>(ds).ToList()[0];
        }
        #endregion
    }
}